[DllImport("kernel32", SetLastError=true, ExactSpelling=true)]
internal static extern Int32 WaitForSingleObject(IntPtr handle, Int32 milliseconds);
None.
None.
public static uint INFINITE = 0xFFFFFFFF;
and use:
WaitForSingleObject(handle, (int)INFINITE);
Edgar - edgarrc(at)gmail.com
private void Run()
{
while (bRunning)
{
try
{
if(WaitForSingleObject(ReceivedEvent,INFINITE) == WAIT_OBJECT_0)
{
// Signaled
DoSomething();
}
}
catch(Exception Ex)
{
// An exception occurred
//
trhow(Ex);
}
}
}
If you're waiting on a file system object, look at System.IO.FileSystemWatcher
System.Threading.WaitHandle and derivatives (e.g. AutoResetEvent)